<?php
class city{
	private $id;
	private $code;
	private $name;
	private	$numdealer;
	public $msg = array();
	// set get id
	public function setid($id) {
		$this->id = $id;
	}
	public function getid() {
		return $this->id;
	}
	// set get code
	public function setcode($code) {
		if ($code == "") $this->msg['error'] = "Code không được để trống";
		else $this->code = $code;
	}
	public function getcode() {
		return $this->name;
	}
	// set get name
	public function setname($name) {
		$this->name = $name;
	}
	public function getname() {
		return $this->name;
	}
	public function listall() {
		GLOBAL $db;
		$sql = "SELECT * FROM " . $db->tbl_fix . "city";
		$result = $db->executeQuery ( $sql );
		while ( $rows = mysql_fetch_array ( $result ) ) {
			$return [] = $rows;
		}
		return $return;
	}
	public function listbydealer() {
		GLOBAL $db;
		$sql = "SELECT * FROM " . $db->tbl_fix . "city where `numdealer` > 0";
		$result = $db->executeQuery ( $sql );
		while ( $rows = mysql_fetch_array ( $result ) ) {
			$return [] = $rows;
		}
		return $return;
	}
	public function insert(){
		GLOBAL $db;
		if (count($this->msg['error']) == 0){
			//$arr['id'] = $this->getid();
			$arr['name'] = $this->getname();
			$arr['code'] = $this->getcode();		
			//$arr['url_rewrite'] = $this->getrewrite();		
			$db->record_insert($db->tbl_fix."city", $arr);
		} else {
			return $this->msg;
		}
		
	}
	public function delete() {
		GLOBAL $db;
		$sql = "DELETE FROM " . $db->tbl_fix . "city where `id` ='" . $this->id . "'";
		$db->executeQuery ( $sql );		
	}
}
$city = new city ();
?>